package com.ttdev.mmms.controller.activity;

import com.ttdev.mmms.entity.Activity;
import com.ttdev.mmms.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 活动控制层
 */
@Controller
@RequestMapping("/storeActivity")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @GetMapping("/select")
    //会员查询活动
    public ModelAndView findAll(){
        List<Activity> list = activityService.findAll();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("member/selectMemberActivity");
        modelAndView.addObject("activitySelect",list);
        return modelAndView;
    }

    @RequestMapping("/addActivity")
    public String add(Activity activity) {
        int i = activityService.add(activity);
//        System.out.println(i);
        return "redirect:/storeActivity/select1";
    }

    //商家查询活动
    @RequestMapping("/select1")
    public ModelAndView findAll1(){
        List<Activity> list = activityService.findAll1();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("activity/selectActivity");
        modelAndView.addObject("activitySelect",list);
        return modelAndView;
    }
    @RequestMapping("/update/{id}")
    public ModelAndView updateId(@PathVariable("id") int id){
        List<Activity> list = activityService.queryMember(id);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("activity/updateActivity");
        modelAndView.addObject("list",list);
        return modelAndView;
    }
    //修改信息
    @RequestMapping("/upd")
    public String updateId(Activity activity){
        int i = activityService.update(activity);
        return "redirect:/storeActivity/select1";
    }
    @RequestMapping("/delete/{id}")
    public String delete (@PathVariable("id") Integer id) {
        int i = activityService.delete(id);
        return "store/storeIndex";
   /* //删除信息
    @RequestMapping("/delete/{cardId}")
    public String delete (@PathVariable("cardId") Integer cardId){
        int i = activityService.delete(cardId);
        return "redirect:/memberInFo/select";
    }
    //修改信息
    @RequestMapping("/upd")
    public String updateId(Activity activity){
        int i = activityService.update(activity);
        return "redirect:/memberInFo/select";
    }*/
    }
}
